// var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
const session = require('cookie-session');

var login = require('./routes/login.js');
var register = require('./routes/register.js');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// post接参
app.use(express.json());
app.use(express.urlencoded({ extended: false }));



app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(session({
  keys:['hhhh','jdkfkdg']
}))
app.use(login);
app.use(register);

app.use(function(req, res, next) {
 res.send({code:404,msg:'error'})
});

// error handler
app.use(function(err, req, res, next) {
  res.render('public',{end:err})
});

module.exports = app;
